<template>
	<view class="content_box" :style="'height:'+viewHeight+'px;'">
		<view class="u-flex u-col-center wrapper-box">
			<view class="scroll-box" style="background-color: #F6F6F6;">
				<scroll-view class="left u-flex-col u-col-center" enable-back-to-top scroll-y>
					<view class="type-list u-ellipsis-1" :class="[{ 'list-active': listId == index }]"
						v-for="(item, index) in categoryData" :key="index" @tap="onType(index)">
						<view class="line" :class="[{ 'line-active': listId == index }]"></view>
						{{ item.name }}
					</view>
					<view class="hack-tabbar"></view>
				</scroll-view>
			</view>
			<view style="height: 100%;width: 100%;">
				<scroll-view scroll-y class="scroll-box" enable-back-to-top scroll-with-animation>
					<view class="right" v-if="categoryData.length">
						<image class="type-img" v-if="categoryData[listId].image" :src="categoryData[listId].image"
							mode="aspectFill"></image>

						<view class="item-list" v-for="(list, index1) in categoryData[listId].children" :key="index1">
							<view class="type-box u-flex u-row-between u-col-center">
								<text class="type-title">{{ list.name }}</text>
								<view class="more u-flex u-col-center"
									@tap="jump('/pages/goods/list', { id: list.id })">
									<u-icon name="arrow-right" space="1" label="查看更多" labelPos="left" labelSize="12" color="#000000" size="14"></u-icon>
								</view>
							</view>
							<view class="item-box u-flex">
								<view class="u-flex-col goods-item" @tap="jump('/pages/goods/list', { id: mlist.id })"
									v-for="(mlist, index2) in list.children" :key="index2">
									<image class="item-img" lazy-load :src="mlist.image" mode="aspectFill"></image>
									<view class="item-title u-ellipsis-1 ">{{ mlist.name }}</view>
								</view>
							</view>
						</view>

						<!-- 缺省页 -->
						<view v-show="!categoryData[listId].children.length">
							<u-empty marginTop="60%" icon='https://file.shopro.top/imgs/empty/empty_goods.png' width="260" height="260" text="暂无该商品，还有更多好货等着你噢~">
							</u-empty>
						</view>
						<view class="hack-tabbar"></view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				//一级分类id
				listId: 0,
				categoryData: [],
				//可视高度
				viewHeight: 0,
			};
		},
		computed: {},
		onLoad() {
			this.getCategory();
		},
		onReady() {
			//获取屏幕高度
			uni.getSystemInfo({
				success: (res) => {
					this.viewHeight = res.windowHeight
				}
			})
		},
		methods: {
			//获取分类数据
			getCategory() {
				uni.request({
					url: "https://demo.shopro.top/addons/shopro/category?id=43",
					success: (res) => {
						this.categoryData = res.data.data.children
					}
				})
			},
			//切换分类
			onType(id) {
				this.listId = id;
			},
			// 路由跳转
			jump(path, parmas) {
				console.log("我要跳转")
			}
		}
	};
</script>

<style lang="scss">
	@import url("../../static/css/common.css");

	.hack-tabbar {
		height: calc(100rpx + env(safe-area-inset-bottom) / 2);
		width: 100%;
	}

	.content_box {
		margin-top: 1upx;
		display: flex;
		flex-direction: column;
		overflow: hidden;
		height: 100%;
	}

	.wrapper-box {
		flex: 1;
		margin-top: 1upx;
		height: 100%;
	}

	.scroll-box {
		height: 100%;
		flex: 1;
		background: #fff;
	}

	.left {
		width: 200upx;
		height: 100%;
		flex: 1;

		.list-active {
			background: #fff;
			color: #333333 !important;
			font-weight: bold !important;
		}

		.line-active {
			background: #e6b873;
		}

		.type-list {
			height: 84upx;
			position: relative;
			width: 200rpx;
			padding-left: 16rpx;
			line-height: 84rpx;
			font-size: 28upx;
			font-weight: 400;
			color: rgba(102, 102, 102, 1);

			.line {
				width: 10upx;
				height: 100%;
				position: absolute;
				left: 0;
			}
		}
	}

	.right {
		padding: 0 30upx;
		flex: 1;
		height: 100%;

		.type-img {
			width: 505rpx;
			height: 150rpx;
			background: #ccc;
			border-radius: 10rpx;
			margin-top: 30rpx;
		}

		.item-list {
			.type-box {
				height: 84rpx;

				.type-title {
					font-size: 28rpx;
					font-weight: bold;
				}

				.more {
					font-size: 26rpx;
					color: #999;
				}
			}

			.item-box {
				flex-wrap: wrap;

				.goods-item {
					margin-right: 20rpx;
					margin-bottom: 20rpx;

					&:nth-child(3n) {
						margin-right: 0;
					}

					.item-img {
						width: 150rpx;
						height: 150rpx;
						background: #f5f5f5;
						border-radius: 6rpx;
					}

					.item-title {
						font-size: 24rpx;
						line-height: 24rpx;
						margin-top: 10rpx;
						width: 150rpx;
						text-align: center;
					}
				}
			}
		}
	}
</style>